﻿using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;

namespace WebApi
{
    /// <summary>
    /// ServiceBase
    /// </summary>
    public class ServiceBase
    {
        /// <summary>
        /// 注册服务
        /// </summary>
        /// <param name="services"></param>
        public static void ServiceRegister(IServiceCollection services)
        {
            ServicesProvider = services.BuildServiceProvider();
        }
        /// <summary>
        /// 获取指定接口下的所有注册到库中对应的对象的结合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IEnumerable<T> GetFromServiceRepertory<T>()
        {
            return ServicesProvider.GetServices<T>();
        }
        /// <summary>
        /// 获取指定接口下的所有注册到库中对应的对象的结合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Get<T>()
        {
            return ServicesProvider.GetService<T>();
        }
        static ServiceProvider ServicesProvider { get; set; }
    }
}
